<%@page import="com.sdry.entity.base.Staff"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<jsp:include page="../../common.jsp"></jsp:include>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>合同协议信息</title>
    <%
        String path = request.getContextPath();
    %>
    <%--ueditorUE--%>
    <script type="text/javascript" charset="utf-8" src="<%=path %>/statics/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="<%=path %>/statics/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="<%=path %>/statics/ueditor/lang/zh-cn/zh-cn.js"></script>
<%
    Staff staff = (Staff)session.getAttribute("staff");
    String dname = null;
    if(staff != null){
      if(staff.getDepartment() != null){
	dname = staff.getDepartment().getDname();
        }
    }
  %>
    <style>
        /*初始化编辑器边框*/
        .edui-default .edui-editor {
            border: 0px solid #d4d4d4;
        }
        /*初始化编辑器高度,默认320*/
        #edui1_iframeholder{
            height: 80vh !important
        }
    </style>
    
    <style type="text/css">
    	.d1	{
    		display: none;
    	}
    </style>
    <script type="text/javascript">
        //ueditorUE 初始化文本编辑器
        //var ue = UE.getEditor('content');
        var ue = UE.getEditor('html',{
            //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
            toolbars:[],
            //关闭字数统计
            wordCount:false,
            //默认的编辑区域高度
            initialFrameWidth:null,
            //initialFrameHeight:null,  //初始化编辑器高度,默认320
            //更多其他参数，请参考ueditor.config.js中的配置项
        });
        //ueditorUE 去掉本地保存成功的提示框！
        ue.ready(function () {
            $(".edui-editor-messageholder.edui-default").css({ "visibility": "hidden" });
            ue.setDisabled();
        });
    </script>
    <script type="text/javascript">
        $(function () {
        	$("#exampleModal1").on('hidden.bs.modal',function(){
        		window.location.reload();
        	})
            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();
            //初始化提示框的位置：top-center，bottom-left，bottom-right
            toastr.options.positionClass = 'toast-top-center';
            
            
         
        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_table').bootstrapTable({
                    url: "${pageContext.request.contextPath}/billForm/selectbillFormList.do",
                    method: 'get',                      //请求方式（*）
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber:1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [10, 20, 30],        //可供选择的每页的行数（*）
                    strictSearch: true,
                    minimumCountColumns: 2,             //最少允许的列数
                    clickToSelect: true,                //是否启用点击选中行
                    //height: 550,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "aid",                     //每一行的唯一标识，一般为主键列
                    detailView: false,                   //是否显示父子表
                    showFooter:true, //开启底部
                    columns: [{
                        checkbox: true,
                        footerFormatter: function (value) {
                            var count = 0;
                            console.log(value.billFormMoney);
                            for (var i=0; i<value.length;i++) {
                                //count += parseFloat(JSON.parse(JSON.stringify(value[i].billFormMoney)).entrysalary);
                                count +=  Number(value[i].billFormMoney);
                            }
                            return "统计金额："+count;
                        }
                    }, {
                        field:'billFormId',
                        visible: false,
                        title:"编号",
                        align:'center'
                    },{
                        field:'aid',
                        visible: false,
                        title:"文档id",
                        align:'center'
                    },{
                        field:'billFormName',
                        title:"项目名称",
                        align:'center',
                        formatter: function(value, row, index){
                        	var xs = value; 
                        	if(value.length > 5){
                        		xs = "<span title='"+value+"'>"+value.substring(0,5)+"..."+"</span>";
                        	}
                            return xs;  
                        }
                    },{
                        field:'bfremark13',
                        title:"标题",
                        align:'center',
                        formatter: function(value, row, index){
                        	var xs = value; 
                        	if(value.length > 5){
                        		xs = "<span title='"+value+"'>"+value.substring(0,5)+"..."+"</span>";
                        	}
                            return xs;  
                        }
                    },{
                        field:'billFormType',
                        title:"单据类型",
                        align:'center',
                        formatter: function(value, row, index){
                        	var xs = value; 
                        	if(value.length > 5){
                        		xs = "<span title='"+value+"'>"+value.substring(0,5)+"..."+"</span>";
                        	}
                            return xs;  
                        }
                    },{
                        field:'billFormTime',
                        title:"领款时间",
                        align:'center',
                        formatter : function(value, row, index) {
                        	value = $.trim(value);
                        	if(value == "-00-00"){
                        		value = ""
                            }
                            return value;
                        },
                    },{
                        field:'billFormItem',
                        title:"领款事项",
                        align:'center',
                        formatter: function(value, row, index){
                        	var xs = value; 
                        	if(value.length > 5){
                        		xs = "<span title='"+value+"'>"+value.substring(0,5)+"..."+"</span>";
                        	}
                            return xs;  
                        }
                    },{
                        field:'billFormMoney',
                        title:"领款金额",
                        align:'center',
                        
                    },{
                        field:'bfremark14',
                       	title : '审批状态',
                        align:'center',
           				formatter: function (value, row, index) {
           					console.log(row)
           					if(value == null || value == ""){
           						return '未审批';
           					}else{
           						var deptLength = row.bfremark15.split(",").length;
        						if (row.bfremark15.indexOf('财务部') != -1) {
        							if (deptLength == 2) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'b1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批通过';
        									}
        								}
        							}
        							if (deptLength == 3) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'c1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批通过';
        									}
        								}
        							}
        							if (deptLength == 4) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'd1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批通过';
        									}
        								}
        							}
        							if (value == '0') {
        								return '审批中';
        							} 
        							if (value.indexOf('2') != -1) {
        								return '已驳回(已结算)';
        							}
        						} else {
        							if (deptLength == 1) {
        								if (value.indexOf('1') != -1) {
        									return '审批通过(已结算)';
        								} 
        							}
        							if (deptLength == 2) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'b1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批中';
        									}
        								}
        							}
        							if (deptLength == 3) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'c1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批中';
        									}
        								}
        							}
        							if (deptLength == 4) {
        								if (value.indexOf('1') != -1) {
        									if (value == 'd1') {
        										return '审批通过(已结算)';
        									} else {
        										return '审批中';
        									}
        								}
        							}
        							if (value == '0') {
        								return '审批中';
        							} 
        							if (value.indexOf('2') != -1) {
        								return '已驳回(已结算)';
        							}
        						}
           					}
           					
                         }
                    },{
                        field:'aid',
                        title:"预览",
                        align:'center',
                        width:"80px",
                        formatter : function(cell, row, index) {
                            cell ='<button type="button" id="btn_preview" class="btn btn-primary" onclick="preview('+row.aid+')">预览</button>';
                            return cell;
                        },
                    },],
                    onPostBody:function () {
                        //合并页脚
                        merge_footer();
                      }
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    page: params.offset/params.limit+1,   //页面大小
                    rows: params.limit,  //页码
                    billFormType:$.trim($('#billFormTypeTJ').val()),
                    billFormName:$.trim($('#billFormNameTJ').val()),
                    bfremark12:'${bfremark12}',
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {
            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
                //初始化页面上面的按钮事件
            };

            return oInit;
        };
		//	预览
        function preview(tid) {
            $.ajax({
                url: '/agreement/selectAgreementById.do' ,
                type: 'post',
                async:false,
                dataType:'json',
                data:"id="+tid,
                success: function (data) {
                    if(data.html == null){
                        toastr.warning('该内容为空');
                    }else{
                        ue.setContent(data.html);
                        $('#exampleModal').modal(open);
                    }
                },
            });
        }
        
		
      //合并页脚
        function merge_footer() {
          //获取table表中footer 并获取到这一行的所有列
          var footer_tbody = $('.fixed-table-footer table tbody');
          var footer_tr = footer_tbody.find('>tr');
          var footer_td = footer_tr.find('>td');
          var footer_td_1 = footer_td.eq(0);
          //由于我们这里做统计只需要两列，故可以将除第一列与最后一列的列全部隐藏，然后再设置第一列跨列
          //遍历隐藏中间的列 下标从1开始
          for(var i=1;i<footer_td.length;i++) {
            footer_td.eq(i).hide();
          }
          //设置跨列
          footer_td_1.attr('colspan', footer_td.length-1).show();
          //这里可以根据自己的表格来设置列的宽度 使对齐
          footer_td_1.attr('width', "910px").show();
          footer_td_1.attr('align', "right").show();
        }

        //判断本页是否数据是否为空，如果为空跳转至第一页
        function refresh(){
            setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                var row=$('#tb_table').bootstrapTable('getData');
                if(row.length == 0){
                    $("#tb_table").bootstrapTable("refreshOptions",{pageNumber:1});
                }
            },1000);
        }
        //删除
        function doDelete() {
            var row = $.map($("#tb_table").bootstrapTable('getSelections'),function(row){
                return row ;
            });
            if (row.length == 0) {
                toastr.warning('请至少选择一条数据!');
            }else{
                var ids = "";
                var names = "";
                for(var i = 0;i < row.length;i++){
                	if(i == 0 || i == "0"){
                        ids += row[i].billFormId;
                    }else{
                        ids += "," + row[i].billFormId;
                    }
                }
                
                	
                //询问框
                Ewin.confirm({ message: "确认要删除选择的数据吗？" }).on(function (e) {
                    if (!e) {
                        return;
                    }
                    var url = "${pageContext.request.contextPath }/agreement/deleteAgreement.do";
                    $.post(url, "ids="+ids, function(data) {
                        if (data >= 1) {
                            toastr.success('删除成功');
                            setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                                $('#tb_table').bootstrapTable('refresh');
                                refresh();
                            },1000);
                        } else {
                            toastr.error('删除失败');
                            setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
                                $('#tb_table').bootstrapTable('refresh');
                                refresh();
                            },1000);
                        }
                    });
                });

            }
        }

        //刷新表格
        function seach() {
            $("#tb_table").bootstrapTable("refreshOptions",{pageNumber:1});
        }
        
        
    </script>
    <style type="text/css">
    	.panel{
    		margin-bottom: 0px;
    	}
    	.panel-body{
    		padding: 5px;
    	}
    	.form-group{
    		margin: 0px;
    	}
    </style>
</head>
<body>
<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <!-- <div class="panel-heading">查询条件</div> -->
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <div class="form-group">
                    <label class="control-label col-sm-1" for="billFormTypeTJ">单据类型</label>
                    <div class="col-sm-2">
                        <input type="text" class="form-control" id="billFormTypeTJ">
                    </div>
                    <label class="control-label col-sm-1" for="billFormNameTJ">项目名称</label>
                    <div class="col-sm-2">
                		<input type="text" class="form-control" id="billFormNameTJ">
                    </div>
                    <div class="col-sm-6">
                        <button type="button" id="btn_query" class="btn btn-primary" onclick="seach()">查询</button>
                        &nbsp;&nbsp;
                        <!-- <button id="btn_add" type="button" class="btn btn-default" onclick="doAdd()">
				            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				        </button> -->
				        <!-- <button id="btn_edit" type="button" class="btn btn-default" onclick="doView()">
				            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>修改
				        </button> 
				       <button id="btn_delete" type="button" class="btn btn-default" onclick="doDelete()">
				            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除
				        </button>  -->
				       <!-- <button id="btn_delete" type="button" class="btn btn-default" onclick="doSub()">
				            <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>提交审批
				        </button> -->
                    </div>
                </div>
            </form>
        </div>
    </div>
    <table id="tb_table"></table>
</div>

<div class="modal fade bs-example-modal-lg" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close closefm" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="exampleModalLabel">
                    <span style="font-size:13px">预览</span>&nbsp;&nbsp;&nbsp;&nbsp;
	                <button type="button" class="btn btn-default" onclick="dy()">
	                    <span class="glyphicon glyphicon-print" aria-hidden="true"></span>
	                </button>
                </h4>
                <script type="text/javascript">
                    function dy() {
                    	var css="<style>"
                            +"table {border-collapse: collapse;" +
                                "border:1px #ddd solid;" +
                           "}"
                           +"table tr td {" +
                                "border:1px #ddd solid;" +
                           "}"
                            +"</style>";
                        var printHtml = css + ue.getContent();
                    	printpage(printHtml)
                    }
                   
                    function printpage(printHtml){    
                    	var wind = window.open("",'newwindow', 'top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');
                    	wind.document.body.innerHTML = printHtml;
                    	wind.print();
                    	return false; 
                    }
                </script>

            </div>
            <div class="modal-body" >
                <textarea id="html" name="html"></textarea>
            </div>
        </div>
    </div>
</div>
</body>
</html>